package com.briup.cms.web.controller;

import com.briup.cms.bean.Notes;
import com.briup.cms.service.INotesService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "笔记模板接口测试")
@RestController
@RequestMapping("/notes")
public class NotesController {

    @Autowired
    private INotesService notesService;


    @ApiOperation("查询所有")
    @GetMapping("findAll")
    public Message findAll(){
        List<Notes> list=notesService.findAll();
        return MessageUtil.success(list);
    }

    @ApiOperation("保存更新")
    @GetMapping("saveOrUpdate")
    public Message saveOrUpdate(Notes notes){

        notesService.saveOrUpdate(notes);
        return MessageUtil.success("操作成功");
    }

    @ApiOperation("删除")
    @PostMapping("deleteById")
    public Message deleteById(long id){
        notesService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

}
